/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.biz.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.exception.BizException;
import me.zhengjie.modules.biz.domain.Vip;
import me.zhengjie.modules.biz.domain.req.VipDetailReq;
import me.zhengjie.modules.biz.service.VipService;
import me.zhengjie.modules.biz.domain.vo.VipQueryCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.utils.PageResult;

/**
* @author yiwei.he
* @date 2024-03-22
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "vip设置管理")
@RequestMapping("/api/vip")
public class VipController {

    private final VipService vipService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
//    @PreAuthorize("@el.check()")
    public void exportVip(HttpServletResponse response, VipQueryCriteria criteria) throws IOException {
        vipService.download(vipService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询vip设置")
    @ApiOperation("查询vip设置")
//    @PreAuthorize("@el.check()")
    public ResponseEntity<PageResult<Vip>> queryVip(VipQueryCriteria criteria, Page<Object> page){
        return new ResponseEntity<>(vipService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增vip设置")
    @ApiOperation("新增vip设置")
//    @PreAuthorize("@el.check()")
    public ResponseEntity<Object> createVip(@Validated @RequestBody Vip resources) throws BizException {
        vipService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改vip设置")
    @ApiOperation("修改vip设置")
//    @PreAuthorize("@el.check()")
    public ResponseEntity<Object> updateVip(@Validated @RequestBody Vip resources){
        vipService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PostMapping("/detail")
    @Log("vip详情")
    @ApiOperation("vip详情")
    public ResponseEntity<Vip> getVip(@Validated @RequestBody VipDetailReq req) throws BizException {
        return new ResponseEntity<>(vipService.getVip(req),HttpStatus.OK);
    }


//    @DeleteMapping
//    @Log("删除vip设置")
//    @ApiOperation("删除vip设置")
//    @PreAuthorize("@el.check()")
//    public ResponseEntity<Object> deleteVip(@RequestBody List<Long> ids) {
//        vipService.deleteAll(ids);
//        return new ResponseEntity<>(HttpStatus.OK);
//    }
}